import 'package:flutter/material.dart';

//表单页面接收上个页面传递过来的参数
class FormPage extends StatefulWidget {
  //定义参数，如果没传递参数，则默认是新闻，若传递参数，则为参数
  final String title;
  final int aid;

  const FormPage({
    super.key,
    this.title = "新闻",
    required this.aid,
  });

  @override
  State<FormPage> createState() => _FormPageState();
}

class _FormPageState extends State<FormPage> {

  //生命周期函数获取aid值
  @override
  void initState() {
    super.initState();
    print(widget.aid);
    print(widget.title);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      floatingActionButton: FloatingActionButton(
        onPressed: (){
          //返回到上个页面
          Navigator.pop(context);
        },
        child: const Icon(Icons.home),
      ),

      appBar: AppBar(
        //动态获取定义的title
        title: Text("${widget.title}"),
      ),
      body: const Center(
        child: Text("表单页面"),
      ),
    );
  }
}


